﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SearchWebApplication.Models;
using SearchWebApplication.Classes;

namespace SearchWebApplication.Controllers
{
    public class HomeController : Controller
    {
        public ContactContext db;
        public ContactSearcher search;

        public HomeController()
            : base()
        {
            this.db = new ContactContext();
            this.search = new ContactSearcher(db);
        }

        public ActionResult Index()
        {
            return View();
        }

        
        public ActionResult Results(FormCollection collection)
        {
            List<Contact> l;

            l = db.Contacts.ToList<Contact>();
            l = search.search(collection["SearchTerm"]);

            return View(l);
        }

        public ActionResult Details(string id)
        {
            Contact contact = db.Contacts.Find(int.Parse(id));
            ViewBag.Message = id;
            return View(contact);

        }

    }

}
